<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package.Mapper}.${table.mapperName}">

<#if enableCache>
    <!-- 开启二级缓存 -->
    <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>

</#if>
<#assign alias="${table.name?lower_case?substring(0,1)}${(table.name?index_of('_')!=-1)?string(table.name?lower_case?substring(table.name?index_of('_')+1,table.name?index_of('_')+2),'')}" />

<#if baseResultMap>
    <!-- (${table.name})通用查询映射结果,${table.comment} -->
    <resultMap id="ResultMap" type="${package.Entity}.${entity}">
<#list table.fields as field>
<#if field.keyFlag><#--生成主键排在第一位-->
        <id column="${field.name}" property="${field.propertyName}"/>
</#if>
</#list>
<#list table.commonFields as field><#--生成公共字段 -->
    <result column="${field.name}" property="${field.propertyName}"/>
</#list>
<#list table.fields as field>
<#if !field.keyFlag><#--生成普通字段 -->
        <result column="${field.name}" property="${field.propertyName}"/>
</#if>
</#list>
    </resultMap>

</#if>
<#if baseColumnList>
    <!-- 通用查询结果列 -->
    <sql id="ColumnList">
        <#list table.fields as field><#if field_index!=(table.fields?size - 1)>${alias}.${field.name}, <#else>${alias}.${field.name}</#if></#list>
    </sql>
</#if>

    <!-- 通用查询详情结果列 -->
    <sql id="ColumnDetails">
        <#list table.fields as field><#if field_index!=(table.fields?size - 1)>${alias}.${field.name} as ${table.name?lower_case}_${field.name}, <#else>${alias}.${field.name} as ${table.name?lower_case}_${field.name}</#if></#list>
    </sql>

    <!--(${table.name})通用查询-->
    <sql id="DefaultSelect">
        select <include refid="ColumnList"/> from ${table.name} as ${alias} <#list table.fields as field><#if (logicDeleteFieldName!"") == field.name>where ${alias}.${field.name}=0</#if></#list>
    </sql>

</mapper>
